package com.sugon.entity;

import com.sugon.util.Forbidden;
import lombok.Data;
import lombok.experimental.Accessors;
import org.hibernate.validator.constraints.Length;

import javax.validation.constraints.AssertFalse;
import javax.validation.constraints.DecimalMin;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.Pattern;

/**
 * @author luoyuan
 * @create 2018-11-19-下午10:00
 */
@Data  //次注解可自动生成set get 方法
@Accessors(chain = true) //次注解代表可以链式赋值
public class Demo {

    private final static String pattern = "^[a-zA-Z0-9_-]+$";

    //验证名称不能为空以及组成方式
    @NotEmpty(message = "名字不能为空")
    @Pattern(regexp = pattern, message = "名字只有有大小写字母，数字和横线组成")
    //使用自定义验证规则
    @Forbidden(message = "系统关键字不能使用")
    private String name;

    //验证密码长度
    @Length(min = 8, max = 16, message = "密码长度应为8-16位")
    private String password;
    //验证年龄必须大于1
    @DecimalMin(value = "1", message = "年龄不合法")
    private Integer age;

    //验证必须为flase
    @AssertFalse(message = "必须为false")
    private Boolean isFalse;

    //验证身份证格式
    @Pattern(regexp = "^(\\d{18,18}|\\d{15,15}|(\\d{17,17}[x|X]))$", message = "身份证格式错误")
    private String idCard;


}
